import request from "@/utils/request";

// 新增文章
export const articleAddApi = (articleData) => request.post('/article', articleData)

// 条件分页查询【id和state不是必须的】
// export const articleListApi = (pageNum, pageSize, categoryId, state) => request.get(`/article?pageNum=${pageNum}&pageSize=${pageSize}&categoryId=${categoryId}&state=${state}`)

// 方法一：条件拼接参数
// export const articleListApi = (pageNum, pageSize, categoryId, state) => {
//   let url = `/article?pageNum=${pageNum}&pageSize=${pageSize}`;
//   if (categoryId !== undefined && categoryId !== null) {
//     url += `&categoryId=${categoryId}`;
//   }
//   if (state !== undefined && state !== null) {
//     url += `&state=${state}`;
//   }
//   return request.get(url);
// }  
// 方法二：使用URLSearchParams
// export const articleListApi = (pageNum, pageSize, categoryId, state) => {
//   const params = new URLSearchParams({
//     pageNum,
//     pageSize,
//     ...(categoryId !== undefined && { categoryId }),
//     ...(state !== undefined && { state })
//   });
//   return request.get(`/article?${params.toString()}`);
// }
// 方法三：使用params
export const articleListApi = (params)=>request.get('./article',{params:params})

// 删除文章
export const articleDeleteApi = (id)=>request.delete('/article?id='+id)

// 修改文章
export const articleUpdateApi = (articleData) => request.put('/article',articleData)

// 获取某个文章详细信息【暂未用到】